package com.shop.autoshop.service.imp;

import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
import com.shop.autoshop.pay.alipay.AliPayConfiguration;
import com.shop.autoshop.pay.alipay.AlipayNotifyBean;
import com.shop.autoshop.pay.wxpay.WxPayConfiguration;
import com.shop.autoshop.service.PayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;

@Slf4j
@Service
public class PayServiceImpl implements PayService {


    @Resource
    private AliPayConfiguration aliPayConfiguration;

    @Resource
    private WxPayConfiguration wxPayConfiguration;
    @Override
    public String notifyAlipay(AlipayNotifyBean alipayNotifyBean) {
        // 商户订单号
        String orderNum = alipayNotifyBean.getOut_trade_no();
        String outTradeNo = alipayNotifyBean.getTrade_no();
        String gmt_payment = alipayNotifyBean.getGmt_payment();
        Date payTime = aliPayConfiguration.alipayNotifyDateFormat(gmt_payment);
        BigDecimal totalAmount = new BigDecimal(alipayNotifyBean.getTotal_amount());

        //TODO 修改订单状态，记录日志

        return null;
    }

    @Override
    public boolean notifyWxpay(WxPayOrderNotifyResult notifyResult) {

        //自定义数据
        String attach = notifyResult.getAttach();
        // 我们系统订单编号
        String outTradeNo = notifyResult.getOutTradeNo();
        // 外部订单编号
        String transactionId = notifyResult.getTransactionId();
        String timeEnd = notifyResult.getTimeEnd();
        Date payTime = wxPayConfiguration.wxNotifyDateFormate(timeEnd);

        BigDecimal payPrice = new BigDecimal(notifyResult.getCashFee()).divide(new BigDecimal(100));


        //TODO 修改订单状态，记录日志

        return false;
    }
}
